package com.nus.servlets;

import com.nus.beans.Project;
import com.nus.database.ProjectsDBManager;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;

/**
 * Created by IntelliJ IDEA.
 * User: dell
 * Date: 11/2/12
 * Time: 10:51 PM
 * To change this template use File | Settings | File Templates.
 */
public class DeleteProjectRemarkServlet extends AbstractServlet {
    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        String projectRemarkId = request.getParameter("projectRemark");

        Connection connection = getUserDatabaseConnection(request);
        ProjectsDBManager projectManager = new ProjectsDBManager(connection);
        projectManager.deleteProjectRemark(Integer.parseInt(projectRemarkId));

        projectManager.close();

        Project project = (Project) request.getSession().getAttribute("project");

        request.setAttribute("projects", project.getId());
        RequestDispatcher dispatcher = request.getRequestDispatcher("viewProjectRemarks.do");
        dispatcher.forward(request, response);
    }
}
